﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using System.Diagnostics;

namespace AGrandVenture
{
    public static class DataManager
    {
        //The purpose of this class is to provide cached data to the game as needed to improve performance and reduce HDD access.
        //Data Values need to be set at game launch.

        private static ContentManager contentManager;

        #region Lists

        //Add new datatypes here
        private static List<string> armArmorNames, chestArmorNames, feetArmorNames, greyItemSuffix, greyItemPrefix, handArmorNames, headArmorNames, legArmorNames, shieldNames, waistArmorNames, weaponNames, earringNames, neckpieceNames;

        //Add read only accessor for your new datatype here.
        public static List<string> ArmArmorNames
        {
            get 
            {
                if (armArmorNames == null)
                    armArmorNames = new List<string>();

                return armArmorNames;
            }
            
        }

        public static List<string> EarringNames
        {
            get
            {
                if (earringNames == null)
                    earringNames = new List<string>();

                return earringNames;
            }

        }

        public static List<string> ChestArmorNames
        {
            get
            {
                if (chestArmorNames == null)
                    chestArmorNames = new List<string>();

                return chestArmorNames;
            }

        }

        public static List<string> FeetArmorNames
        {
            get
            {
                if (feetArmorNames == null)
                    feetArmorNames = new List<string>();

                return feetArmorNames;
            }

        }

        public static List<string> GreyItemSuffix
        {
            get
            {
                if (greyItemSuffix == null)
                    greyItemSuffix = new List<string>();

                return greyItemSuffix;
            }

        }

        public static List<string> GreyItemPrefix
        {
            get
            {
                if (greyItemPrefix == null)
                    greyItemPrefix = new List<string>();

                return greyItemPrefix;
            }

        }

        public static List<string> HandArmorNames
        {
            get
            {
                if (handArmorNames == null)
                    handArmorNames = new List<string>();

                return handArmorNames;
            }

        }

        public static List<string> HeadArmorNames
        {
            get
            {
                if (headArmorNames == null)
                    headArmorNames = new List<string>();

                return headArmorNames;
            }

        }

        public static List<string> LegArmorNames
        {
            get
            {
                if (legArmorNames == null)
                    legArmorNames = new List<string>();

                return legArmorNames;
            }

        }

        public static List<string> ShieldNames
        {
            get
            {
                if (shieldNames == null)
                    shieldNames = new List<string>();

                return shieldNames;
            }

        }

        public static List<string> WaistArmorNames
        {
            get
            {
                if (waistArmorNames == null)
                    waistArmorNames = new List<string>();

                return waistArmorNames;
            }

        }

        public static List<string> WeaponNames
        {
            get
            {
                if (weaponNames == null)
                    weaponNames = new List<string>();

                return weaponNames;
            }

        }

        public static List<string> NeckpieceNames
        {
            get
            {
                if (neckpieceNames == null)
                    neckpieceNames = new List<string>();

                return neckpieceNames;
            }

        }


        #endregion

        #region Initialisor
        public static void Initialise(ContentManager content)
        {
            contentManager = content;

            //Load textfiles.  
            
            armArmorNames = LoadTextFile("ArmArmorNames.txt");
            chestArmorNames = LoadTextFile("ChestArmorNames.txt");
            feetArmorNames = LoadTextFile("FeetArmorNames.txt");
            greyItemPrefix = LoadTextFile("GreyItemPrefix.txt");
            greyItemSuffix = LoadTextFile("GreyItemSuffix.txt");
            handArmorNames = LoadTextFile("HandArmorNames.txt");
            headArmorNames = LoadTextFile("HeadArmorNames.txt");
            legArmorNames = LoadTextFile("LegArmorNames.txt");
            shieldNames = LoadTextFile("ShieldNames.txt");
            waistArmorNames = LoadTextFile("WaistArmorNames.txt");
            weaponNames = LoadTextFile("WeaponNames.txt");
            earringNames = LoadTextFile("EarringNames.txt");
            neckpieceNames = LoadTextFile("NeckpieceNames.txt");

        }
        #endregion

        #region private methods
        private static List<string> LoadTextFile(string file)
        {
            List<string> listToReturn = new List<string>();
            string path = ("DataFiles/");

            if (System.IO.File.Exists(path + file) == true)
            {
                using (StreamReader reader = new StreamReader(TitleContainer.OpenStream(path + file)))
                {
                    while (!(reader.Peek() == -1))
                        listToReturn.Add(reader.ReadLine());

                    reader.Close();
                    reader.Dispose();
                }
            }

            return listToReturn;
        }
        #endregion

        #region public methods



        #endregion





    }
}
